﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EIS_desktop
{
    public partial class BalanceHistory : Form
    {
        private PayRoll prform;
        public BalanceHistory()
        {
            InitializeComponent();
        }

        public BalanceHistory(PayRoll objpr)
        {
            InitializeComponent();
            prform = objpr;
        }

        private DataTable GetBalanceHistory()
        {
            string datestr = "1-" + prform.Month + "-" + prform.Year.ToString();

            System.Data.SqlClient.SqlConnection sqlcon = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.AppSettings["constr"]);
            System.Data.SqlClient.SqlCommand sqlcmd = new System.Data.SqlClient.SqlCommand
                ("Select PayPeriod,BalanceWithHeldAmount from PayRoll where EmpId= " + prform.EmployeeId + 
                " and PayPeriod <= dateadd(m,-1,'" + datestr + "')", sqlcon);
            System.Data.SqlClient.SqlDataAdapter sqladp = new System.Data.SqlClient.SqlDataAdapter(sqlcmd);

            DataTable dt = new DataTable();
            sqladp.Fill(dt);
            return dt;
        }

        private void BalanceHistory_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = GetBalanceHistory();
            dataGridView1.Columns[0].DefaultCellStyle.Format = "MMM/yyyy";
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
